package com.campus_information_portal.service.impl;

import com.campus_information_portal.dao.TeacherDao;
import com.campus_information_portal.entity.Teacher;
import com.campus_information_portal.service.TeacherService;
import com.campus_information_portal.util.DateJsonType;
import com.campus_information_portal.util.Message;
import com.campus_information_portal.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author 20155883 万珊
 * @description 老师实现类
 * @project_name TeacherImpl
 * @package com.campus_information_portal.service.impl.TeacherImpl
 * @create 2018-04-26 8:55
 **/
@Service
@Transactional(rollbackFor=Exception.class)
public class TeacherImpl implements TeacherService {
    @Autowired
    private TeacherDao teacherDao;

    /**
     * @param te_num
     * @Description 根据Teacher表中的老师编号查询老师个人信息
     * @author 20155883 万珊
     * @methodName queryTeacherByTeNum
     * @returnType Message
     * @create 2018/4/26 9:05
     **/
    @Cacheable(value = "myCache", key = "'TeacherService.queryTeacherByTeNum'")
    @Override
    public Message queryTeacherByTeNum(int te_num) {
        System.out.println("*************************************************我是Teacher缓存方法*************************************************");
        Teacher teacher = teacherDao.queryTeacherByTeNum(te_num);
        if(teacher!=null){
            return Message.success().add("teacher",teacher);
        }
        return Message.fail().add("0201","查询失败");
    }


    /**
     * @param teacher
     * @Description 修改老师信息表（姓名，性别，身份证，出生年月，民族，电话，籍贯）
     * @author 20155880 房雁颖
     * @methodName updateTeacher
     * @returnType Message
     * @create 2018/4/26 15:26
     **/
    @Override
    public Message updateTeacher(Teacher teacher) {
        boolean flag=teacherDao.updateTeacher(teacher);
        if (flag==true){
            return Message.success();
        }
        return Message.fail().add("0202","更新失败");
    }
    /**
     * @Description 通过老师名字查找id
     * @author 20155878 鄢前州
     * @methodName ququeryte_info_idByte_name
     * @returnType int
     * @create 9:09 2018/5/10
     **/
    @Override
    public int ququeryte_info_idByte_name(String te_name) {
        int te_info_id=teacherDao.ququeryte_info_idByte_name(te_name);
        return te_info_id;
    }
}
